package com.cch.examSystem.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cch.examSystem.entity.ScaleList;
import com.cch.examSystem.entity.ScoreList;

public class ScoreListServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		Date now = new Date();
		SimpleDateFormat datetime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		SimpleDateFormat date = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat time = new SimpleDateFormat("HH:mm");
		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();

		List scoreList = new ArrayList();
		ScoreList score;
		String scaleName = "测试问卷";
		String userName = "测试用户";
		for (int i = 0; i < 6; i++) {
			score = new ScoreList(i, "IT", "java", scaleName + i, userName
					+ i, 80 + i, datetime.format(now));
			scoreList.add(score);
		}
		for (int i = 6; i < 10; i++) {
			score = new ScoreList(i, "IT", "c", scaleName + i, userName
					+ i, 90 + i, datetime.format(now));
			scoreList.add(score);
		}
		for (int i = 10; i < 16; i++) {
			score = new ScoreList(i, "数学", "高数", scaleName + i, userName
					+ i, 90 + i, datetime.format(now));
			scoreList.add(score);
		}
		for (int i = 16; i < 20; i++) {
			score = new ScoreList(i, "数学", "数学与应用数学", scaleName + i, userName
					+ i, 90 + i, datetime.format(now));
			scoreList.add(score);
		}
		/* System.out.println(JSON.toJSONString(scaleList)); */
		request.setAttribute("scoreList", scoreList);
		request.getRequestDispatcher("./manager/scoreList.jsp").forward(
				request, response);
		out.flush();
		out.close();
	}

}
